package com.example.demo;

import com.alibaba.fastjson.JSON;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.api.CreateBuilder;
import org.apache.zookeeper.CreateMode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

@Controller
public class DemoControll {

    @Autowired
    private DemoService demoService;

    @Autowired
    private CuratorFramework curatorFramework;


    @RequestMapping(value = "login")
    @ResponseBody
    public String login( String name,String password){
        System.out.println(String.format("用户:%1$s,密码:%2$s",name,password));
        return null;
    }

    @RequestMapping(value = "zookeeper")
    @ResponseBody
    public String zookeeper(){
        CreateBuilder createBuilder = curatorFramework.create();
        try {
            String s = createBuilder.forPath("/nibbhdao","总重".getBytes());
            String s1 = createBuilder.withMode(CreateMode.EPHEMERAL).forPath("/nbifd");
            System.out.println(s1);
            System.out.println(s);
            curatorFramework.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

}
